#include "stdafx.h"
#include "MaterialManager.h"

#include "Material.h"
#include "TextureManager.h"
#include "ShaderManager.h"
#include "GraphicsResources.h"

using namespace mgfx;
using namespace std;

Material * MaterialManager::createMaterial(const string & key)
{
	assert(mMaterials.find(key) == mMaterials.end());
	Material * mat = new Material;
	mMaterials[key] = mat;
	return mat;
}

Material * MaterialManager::getMaterial(const string & key)
{
	assert(mMaterials.find(key) != mMaterials.end());
	return mMaterials[key];
}

void MaterialManager::init()
{
	Material * mat = createMaterial("Grass");
	mat->Shader = GraphicsResources::getGlobal()->getShaderMgr()->getShader(TEXTURED);
	mat->DiffuseMap = GraphicsResources::getGlobal()->getTextureMgr()->createTex(L"content\\textures\\grass.dds");

	mDefaultMaterial = mat;
}

void MaterialManager::deinit()
{
	for(MaterialMap::iterator it = mMaterials.begin() ; it != mMaterials.end() ; ++it)
		delete it->second;
}